<?php

class Controller extends Smarty
{
    public function __construct(){
        $this->setTemplateDir('./views')
             ->setCompileDir('./runtime/views_c')
             ->setConfigDir('./configs')
             ->setCacheDir('./runtime/caches');
        $this->caching = false;
        $this->cache_lifetime = 30;
    }

    public function __call($fun, $pa)
    {
        echo "<h1>404 not found!!!</h1>";
        exit();
    }

    public function redirect($message, $url=null)
    {
        echo "<script>alert('{$message}')</script>";
        if (empty($url)) {
            //未传递url参数 则回到来之前的页面
            echo "<script>history.back()</script>";
        } else {
            //跳转到指定页面
            echo "<script>location.href='{$url}'</script>";
        }
        
    }
}